package com.ruicar.afs.cloud.channel.channelworkflow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.channel.affiliation.condition.AffiliationCondition;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskApproveRecordService;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskAssignService;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskCreatedService;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskDetailService;
import com.ruicar.afs.cloud.channel.channelworkflow.vo.AffiliationWorkTaskVo;
import com.ruicar.afs.cloud.common.core.exception.AfsBaseException;
import com.ruicar.afs.cloud.common.core.security.util.SecurityUtils;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.workflow.gwt.service.WorkflowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author: panhj
 * @date: 2020/8/14 15:45
 * @description:
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/affiliationWorkFlow")
@Api("挂靠审批")
public class AffiliationWorkFlowController {
    private final WorkTaskAssignService workTaskAssignService;

    @PostMapping(value = "/getAffiliationWorkFlowData")
    @ApiOperation(value = "多条件分页挂靠公司信息列表")
    public IResponse getByCondition(@RequestBody AffiliationCondition condition) {
        Page page = new Page(condition.getPageNumber(), condition.getPageSize());
//        //获取当前用户登录名
//        condition.setUsername(SecurityUtils.getUsername());
        // 先获取登陆人的角色
        List<String> roles =SecurityUtils.getRoles();
        if(roles.size()<=0){
            throw new AfsBaseException("此用户暂无权限查询！");
        }
        IPage<List<AffiliationWorkTaskVo>> affiliationWorkflowInfo = workTaskAssignService.getAffiliationWorkflowInfo(page, condition,roles);
        return IResponse.success(affiliationWorkflowInfo);
    }
}
